#include <functional>
#include <queue>
#include <vector>
#include <iostream>
#include <map>
template<typename T> void print_queue(T& q) {
    while(!q.empty()) {
        std::cout << q.top() << " ";
        q.pop();
    }
    std::cout << '\n';
}
using namespace std;
int main() {
    std::priority_queue<int> q;
    print_queue(q);
    std::priority_queue<int, std::vector<int>, std::greater<int> > q2;

    for(int n : {1,8,5,6,3,4,0,9,7,2})
        q2.push(n);
    map<char,int>a = {{'o',4},{'p',2},{'a',1},{'e',1},{'r',1}};
    auto fn =[](pair<char,int>a1,pair<char,int>a2){return a1.second<a2.second;};
    std::priority_queue<pair<char,int>,std::vector<pair<char,int>>,decltype(fn)>current_frequency(fn);
    for(auto e:a){
        current_frequency.push(pair<char,int>(e.first,e.second));
    }
    string result = "";
    while (!current_frequency.empty()){
        auto elem = current_frequency.top();
        cout<<elem.first<<" "<<elem.second<<endl;
        for(int i=0;i<elem.second;i++)
            result+=elem.first;
        current_frequency.pop();
    }
    cout<<result;

}
